

var oPage = {
	oThis: null, // 当前对象
	oSearch: null,

	yxjsDialog: null, // 影像接收

	current: 1, // 当前页
	size: 20,
	paging: null, // 分页对象
	list: [],

	init: function () {
		this.initState();
		this.initEvent();
	},
	initState: function () {
		this.oThis = $('.mold-list-wp');
		this.oSearch = this.oThis.find('.search-box');

		// 影像接收
		this.yxjsDialog = new TheDialog('#yxjsDialog');
		// 影像下载
		this.yxxzDialog = new TheDialog('#yxxzDialog');
		// 分页
		this.paging = new ThePaging('#moldListPaging', {
			currentChange: function (current) {
				_this.current = current;
				_this.getData();
			}
		})

		this.getData();
	},
	initEvent: function () {
		var _this = this;

		// 点击查询
		this.oSearch.find('.search-btn').on('click', function () {
			_this.current = 1;
			_this.getData();
		})
		
		// 表格查看点击
		this.oThis.find('.com-table-body').on('click', '.see-btn', function () {
			var oBtn = $(this);
			var oTr = oBtn.parent().parent();
			var idx = oTr.attr('idx');
			var oDetail = _this.list[idx];
			pb.storage.set('mold-detail', oDetail);
			window.open('./mold-see.html');
		})

		this.oThis.find('.com-table-body').on('click', '.icon', function () {
			var oBtn = $(this);
			var idx = oBtn.parent().parent().attr('idx');
			var detail = _this.list[idx];
			if (oBtn.hasClass('yxjs-btn')) {
				moldYxjsDialog.show(detail);
			} else if (oBtn.hasClass('yxxz-btn')) {
				moldYxxzDialog.show(detail);
			} else if (oBtn.hasClass('zdjh-btn')) {
				moldZdjhDialog.show(detail);
			} else if (oBtn.hasClass('jm-btn')) {
				moldJmDialog.show(detail);
			} else if (oBtn.hasClass('zm-btn')) {
				moldZmDialog.show(detail);
			} else if (oBtn.hasClass('wjjf-btn')) {
				moldWjjfDialog.show(detail);
			} else if (oBtn.hasClass('swjf-btn')) {
				moldSwjfDialog.show(detail);
			}
		})
	},

	// 查询数据
	getData () {
		var _this = this;
		$.ajax({
			type: 'get',
			url: pb.api + '/task/listData',
			data: {
				applyNo: this.oSearch.find('.applyNo').val(),
				patientNameSpell: this.oSearch.find('.patientNameSpell').val(),
				patientName: this.oSearch.find('.patientName').val(),
				startDate: this.oSearch.find('.start-time').val(),
				endDate: this.oSearch.find('.end-time').val(),
				makingState: this.oSearch.find('.makingState').val(),
				pageNo: this.current,
				pageSize: this.size
			},
			success: function (res) {
				var list = res.list;
				_this.list = list;
				_this.setTbody(list);
				_this.paging.setTotal(res.count);
			}
		})
	},
	setTbody: function (list) {
		var html = '';
		if (list.length) {
			list.forEach((item, index) => {
				var yxjs = item.receiveState == 1 ? 'icongou' : 'iconyou';
				var yxxz = item.downloadState == 1 ? 'icongou' : item.receiveState == 1 ? 'iconyou' : 'iconyou grey';
				var zdjh = item.makePlanState == 1 ? 'icongou' : item.downloadState == 1 ? 'iconyou' : 'iconyou grey';
				var jm = item.modeState == 2 ? 'icongou' : item.makePlanState == 1 ? 'iconyou' : 'iconyou grey';
				var zm = item.makeState == 2 ? 'icongou' : item.modeState == 2 ? 'iconyou' : 'iconyou grey';
				var wjjf = item.fileState == 2 ? 'icongou' : item.makeState == 2 ? 'iconyou' : 'iconyou grey';
				var swjf = item.physicalState == 2 ? 'icongou' : item.fileState == 2 ? 'iconyou' : 'iconyou grey';

				html += '<tr idx="' + index + '">' +
							'<td>' + ((this.current-1)*this.size+index+1) + '</td>' +
							'<td title="' + (item.applyNo || '') +'">' + (item.applyNo || '-') + '</td>' +
							'<td title="' + (item.applyTime || '') +'">' + (item.applyTime || '-') + '</td>' +
							'<td title="' + (item.patientName || '') +'">' + (item.patientName || '-') + '</td>' +
							'<td title="' + (item.sex || '') +'">' + (item.sex || '-') + '</td>' +
							'<td title="' + (item.age || '') +'">' + (item.age || '-') + '</td>' +
							'<td title="' + (item.patientTypeName || '') +'">' + (item.patientTypeName || '-') + '</td>' +
							'<td title="' + (item.deptName || '') +'">' + (item.deptName || '-') + '</td>' +
							'<td title="' + (item.doctorName || '') +'">' + (item.doctorName || '-') + '</td>' +
							'<td title="' + (item.partName || '') +'">' + (item.partName || '-') + '</td>' +
							'<td title="' + (item.checkPointMethod || '') +'">' + (item.checkPointMethod || '-') + '</td>' +
							'<td title="' + (item.modePlanTime || '') +'">' + (item.modePlanTime ? item.modePlanTime.slice(0, 10) : '-') + '</td>' +
							'<td title="' + (item.makePlanTime || '') +'">' + (item.makePlanTime ? item.makePlanTime.slice(0, 10) : '-') + '</td>' +
							'<td title="' + (item.modeActualTime || '') +'">' + (item.modeActualTime  || '-') + '</td>' +
							'<td title="' + (item.makeActualTime || '') +'">' + (item.makeActualTime  || '-') + '</td>' +
							'<td><i class="icon iconfont yxjs-btn ' + yxjs + '"></i></td>' +
							'<td><i class="icon iconfont yxxz-btn ' + yxxz + '"></i></td>' +
							'<td><i class="icon iconfont zdjh-btn ' + zdjh + '"></i></td>' +
							'<td><i class="icon iconfont jm-btn ' + jm + '"></i></td>' +
							'<td><i class="icon iconfont zm-btn ' + zm + '"></i></td>' +
							'<td><i class="icon iconfont wjjf-btn ' + wjjf + '"></i></td>' +
							'<td><i class="icon iconfont swjf-btn ' + swjf + '"></i></td>' +
							'<td>' +
								'<button class="see-btn">查看</button>' +
							'</td>' +
						'</tr>';
			})
		} else {
			html = '<tr class="empty"><td>暂无数据</td></tr>';
		}


		this.oThis.find('.com-table-body tbody').html(html);
	},

}


$(function () {
	oPage.init();
})

